<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0 clientlist" id="list" lay-title="游戏活动管理">
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card hxr-layui-card" id="userlistv">
 					<div class="layui-form layui-card-header hxradmin-card-header">
						<div class="layui-form-item">

 							<div class="layui-inline">
								<label class="layui-form-label">活动状态</label>
								<div class="layui-input-inline">
									<div class="layui-unselect layui-form-select">
										<div class="layui-select-title"><input name="status" type="text" placeholder="请选择状态" value="" readonly class="layui-input layui-unselect"><i
											 class="layui-edge"></i></div>
										<dl class="layui-anim layui-anim-upbit" style="">
											<dd lay-value="" class="layui-select-tips layui-this">请选择状态</dd>
											<dd data='1'>启动</dd>
											<dd data='2'>停用</dd>
										</dl>
									</div>
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn" data-type="reload" id="search">搜索</button>
							</div>
						</div>
					</div>
					<div class="layui-card-body">
						<div>
							<button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
							<button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
						</div>
						<table class="layui-hide" id="list-table" lay-filter="list-table"></table>
						
						<div id="list-toolbar" style="display: none;">
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                                    class="layui-icon layui-icon-edit"></i>编辑</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                                    class="layui-icon layui-icon-delete"></i>删除</a>
                        </div>
						<script type="text/html" id="status">
						  <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" lay-filter="list-tableF"
						   value="{{ d.status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == '1' ? 'checked' : '' }}>
						</script>
						<script type="text/html" id="is_rank">
							{{#  if(d.is_rank==1){ }}
							是
							{{#  }else{ }}
							否
							{{#  } }}
						</script>
						<script type="text/html" id="stars_extra">
							{{#  if(d.stars_extra_arr){  }}
							每拥有
							{{# layui.each(d.stars_extra_arr, function(index, item){     }}
							{{ item['num']}}
							个{{ item['star'] }}星 {{ item['jiage'] }}金币英雄奖励 {{ item['star_fee'] }}元网费,
							{{#  })  }}
							{{#  } }}
						</script>
						<script type="text/html" id="gradings_extra">
							{{#  if(d.gradings_extra_arr){ var aaa= ['无限制', '无段位', '黑铁', '青铜', '白银', '黄金', '白金', '钻石', '大师', '宗师', '王者']; }}
							{{# layui.each(d.gradings_extra_arr, function(index, item){     }}
							{{ aaa[item['gradings_extra']-1]}}奖励 {{ item['gradings_fee'] }}元网费,
							{{#  })  }}
							{{#  } }}
						</script>
		                <script type="text/html" id="grading">
							{{# var aaa= ['无限制', '无段位', '黑铁', '青铜', '白银', '黄金', '白金', '钻石', '大师', '宗师', '王者']; }}
							{{ aaa[d['grading']-1] }}

                		</script>
						<script type="text/html" id="time_type">
							{{#  if(d.time_type==1||!d.time_type){  }}
								每天 {{d.start_time}}--{{d.end_time}}
							{{#  }else if(d.time_type==2){ }}
								每周 {{d.weeks}}的{{d.start_time}}--{{d.end_time}}
							{{#  }else if(d.time_type==3){ }}
								每月 {{d.months}}的{{d.start_time}}--{{d.end_time}}
							{{#  }else if(d.time_type==4){ }}
							{{d.special_date}}{{d.start_time}}--{{d.end_time}}
							{{#  }else if(d.time_type==5){ }}
							{{d.special_star_date}}到{{d.special_star_date}}的{{d.end_time}}--{{d.end_time}}
							{{#  }    }}
						</script>

					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var formurl='game/form',formarea=['800px', '660px'];
	//表格数据渲染
	layui.use(['table', 'form','laydate'], function() {
		var table = layui.table,
			form = layui.form,
			$ = layui.$,laydate=layui.laydate;
			layui.admin.initlist(table,'gentinggame/game_list',275,[
						[{
							type: 'checkbox',
							fixed:'left'
						}, {
							field: 'id',
							title: 'ID',
							width: 50
						},{
							field: 'game_name',
							title: '活动名称',
							width: 100
						},{
							field: 'ranking',
							title: '排名',
							width: 100
						},{
							field: 'grading',
							title: '段位最低标准',
							width: 100,
							templet:'#grading'
						},{
							field: 'internet_fee',
							title: '赠送网费',
							width: 100
						},{
							field: 'stars_extra_arr',
							title: '星级英雄奖励',
							width: 160,
							templet:'#stars_extra'
						},{
							field: 'gradings_extra',
							title: '段位奖励',
							width: 160,
							templet:'#gradings_extra'
						},{
							field: 'start_time',
							title: '活动时间',
							width: 300,
							templet:'#time_type'
						},{
							field: 'is_rank',
							title: '是否排位赛',
							width: 100,
							templet:'#is_rank'
						},{
							field: 'create_time',
							title: '创建时间',
							width: 200,
						},{
							field: 'status',
							title: '状态',
							width: 100,
							fixed:'right',
							templet:'#status'
						},{
							title: '操作',
							toolbar: '#list-toolbar',
							minWidth: 150,
							fixed:'right'
						}]
					])
//监听表格表单操作
		form.on('switch(list-tableF)', function(obj) {
			var json = JSON.parse(decodeURIComponent($(this).data('json')));
			json = table.clearCacheKey(json);
			layui.admin.ajax('gentinggame/update',{
				status:json.status == 1?2:1,
				id:json.id
			}).then(function(res){
				table.reload('list-table');
			}).catch(function(res){});
		});
		form.on('switch(list-tableP)', function(obj) {
			var json = JSON.parse(decodeURIComponent($(this).data('json')));
			json = table.clearCacheKey(json);
			layui.admin.ajax('gentinggame/update',{
				protect:json.protect == 1?0:1,
				//task_id:json.task_id
				id:json.id
			}).then(function(res){
				table.reload('list-table');
			}).catch(function(res){});
		});

		//监听表格操作事件
		table.on('tool(list-table)', function(obj) {
			var data = obj.data;
			//删除
			if (obj.event === 'del') {
				layer.confirm('确定删除' + data.ranking + '?', function(index) {
					layui.admin.delF(table,'gentinggame/delete',{id: data.id});
				});
			} else if (obj.event === 'edit') { //编辑

				layui.admin.pupF('编辑游戏活动', formarea, formurl, 2, data)
			}
		});
		//监听行双击事件
		/* table.on('rowDouble(list-table)', function(obj) {
			//查看详情
			if($('.clientlist').length){
				layui.admin.pupF('任务详情', formarea, formurl, 3, obj.data);
			}
		}); */
		var active = {
			//多行删除
			batchdel: function() {
					layui.admin.delsF(table,'gentinggame/delete','id');
				}
				//添加
				,
			add: function(othis) {
				layui.admin.pupF('添加游戏活动', formarea, formurl, 1, {})
			}
		};
		//操作dom
		$('.layui-btn.layuiadmin-btn-list').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		//搜索
		$('#search').on('click', function() {
			var obj=$(this).parents('.layui-form-item'),

			val2 = obj.find('input[name="status"]').attr('data');
			layui.admin.reloads({

				status:val2
			});
		});
	});
	
    function previewImg(obj) {
        var img = new Image();
        img.src = obj.src;
        //var height = img.height + 50; // 原图片大小
        //var width = img.width; //原图片大小
        var imgHtml = "<img src='" + obj.src + "' width='500px' height='200px'/>"; 
        var width = 'auto';
        var height = 'auto';
          
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            area: [width, height],  // area: [width + 'px',height+'px']  //原图显示
            shadeClose: true,
            scrollbar: false,
            title: "图片预览", //不显示标题  
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响  
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });  
            }
        });
    }
</script>
